package com.course.server.common;

import lombok.Getter;

/**
 * @author yangw
 * @created 2021/3/18
 * @description
 */
@Getter
public enum ResultEnum {

    ILLEGAL_OPERATION(501, "非法操作"),
    ERROR(500, "系统异常"),
    SUCCESS(200, "操作成功"),
    INVALID_PARAM(400, "请求参数异常"),
    // 用户
    LOGIN_ERROR(401, "登录失败,帐号或密码错误"),
    PASSWORD_NOT_MATCH(402, "密码不匹配"),
    USER_CLOSED(403, "帐号已被锁定"),
    USER_NOT_EXIST(404, "帐号不存在"),
    SAVE_USER_ERROR(405, "创建帐号失败"),
    USER_NAME_IS_EXIST(406, "用户名已存在"),
    // 分类
    CATEGORY_NOT_EXIST(600, "分类不存在"),
    CATEGORY_SAME_NAME_EXIST(601, "已有同名分类存在"),
    CATEGORY_HAVE_CHILD(602, "当前分类下还存在子分类"),
    ;

    private final int code;
    private final String msg;

    ResultEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ResultEnum getMessage(int code) {
        for (ResultEnum value : ResultEnum.values()) {
            if (value.getCode() == code) {
                return value;
            }
        }
        return ResultEnum.ERROR;
    }
}
